<?php
	include_once('header.php');
	include_once('menu.php');
	include_once('content.php');
?>

<?php
	 	echo form_open('Search/search', array('class'=>'jNice', 'method'=>'get'));
			echo form_fieldset();
			echo '<p>';
			$nastavenie = array('name'=>'search','style'=>'display: inline; float: left;');
			echo form_hidden('menotabulky', 'odcestovani');
			echo form_input($nastavenie);
			echo form_submit('submit', 'Hľadať').'</p>';
			echo form_fieldset_close(); 
		echo form_close();
	 ?>
	<h3>Zoznam ciest</h3>
        <?php echo form_open(site_url('SluzobneCesty/getAll/odcestovani'), array('id' => 'filter_form', 'method' => 'post')); ?>
        <table cellspacing="0" cellpadding="0">
            <tr>
                <td style="width: 20%;">Mesto</td>
                <td style="width: 20%;">Štát</td>
                <td style="width: 20%;">Organizácia</td>
                <td style="width: 20%;">Osoba</td>
                <td style="width: 20%;">Deň</td>
            </tr>
            <tr>
                <td><?php echo form_dropdown('filter[city]', $cities, @$filter['city'], 'size="1" style="width: 95%;"'); ?></td>
                <td><?php echo form_dropdown('filter[country]', $countries, @$filter['country'], 'size="1" style="width: 95%;"'); ?></td>
                <td><?php echo form_dropdown('filter[organization]', $organizations, @$filter['organization'], 'size="1" style="width: 95%;"'); ?></td>
                <td><?php echo form_dropdown('filter[person_id]', $persons, @$filter['person_id'], 'size="1" style="width: 95%;"'); ?></td>
                <td><?php echo form_input('filter[date]', @$filter['date'], 'style="width: 95%;"'); ?></td>
            </tr>
            <tr>
                <td colspan="5"><?php echo form_submit('submit_button', 'Potvrdiť'); ?></td>
            </tr>
        </table>
        <?php echo form_hidden(array('filter[page]' => $paginationData['current_page'], 'filter[per_page]' => isset($filter['per_page']) ? $filter['per_page'] : 20)); ?>
        <?php echo form_close(); ?>
        <hr />
	<table cellpadding="0" cellspacing="0">                                           
		
	<?php
	if( isset($odcesty) && !empty($odcesty) ){
		foreach ($odcesty as $key => $obj) {
	?>
		<tr>
	        <td><?php echo anchor('SluzobneCesty/ukaz/odcestovani/'.$obj['id'], $obj['country'].'-'.$obj['city']); ?></td>
                <td><?php echo $obj['organization']; ?></td>
                <td><?php echo $obj['date_of_arrival']; ?></td>
                <td><?php echo $obj['date_of_departure']; ?></td>
	        
	        <td class="action">
	        	<?php if($this->session->userdata('logged_in') && $this->session->userdata('admin')){ ?>
	        	<?php echo anchor('SluzobneCesty/zmenCestu/odcestovani/'.$obj['id'],'Zmeň',array('class'=>'edit')); ?>
	        	<?php echo anchor('SluzobneCesty/delete/odcestovani/'.$obj['id'], 'Zrušiť',array('class'=>'delete', 'onclick'=>'return confirm(\'Naozaj si prajete vymazať cestu?\')')); ?>
				<?php } ?> 
				&nbsp;       
	        </td>
	        
	    </tr>
	    
	    
	 <?php 
		} //end foreach 
	} //end if 
	 ?>
	 </table>
         <?php echo form_open(site_url('SluzobneCesty/getAll/odcestovani'), array('id' => 'pagination_form', 'method' => 'post')); ?>
         <div id="strankovanie">
             Stránka: <select name="filter[page]" size="1" id="page_selector"><?php
                for ($i = 1; $i <= $paginationData['total_pages']; $i++) {
                    $current_page = $i == $paginationData['current_page'] ? ' selected="selected"' : '';
                    echo "<option value=\"{$i}\"{$current_page}>{$i}</option>";
                }
             ?></select>
             Ciest na stránku: <?php
                $per_pages = array(20 => 20, 50 => 50, 100 => 100);
                echo form_dropdown('filter[per_page]', $per_pages, isset($filter['per_page']) ? $filter['per_page'] : 20, 'size="1" id="per_page_selector"');
             ?>
         </div>
         <?php echo form_hidden(array(
             'filter[city]' => @$filter['city'],
             'filter[country]' => @$filter['country'],
             'filter[organization]' => @$filter['organization'],
             'filter[person_id]' => @$filter['person_id'],
             'filter[date]' => @$filter['date'],
         )); ?>
         <?php echo form_close(); ?>
	 <?php if($this->session->userdata('logged_in') && $this->session->userdata('admin')){ ?>
	 <h3>Pridanie novej cesty</h3>
	 <?php
		
		echo form_open('SluzobneCesty/add', array('class'=>'jNice'));
			echo form_fieldset();
			echo form_error('city');
			echo '<p>'.form_label('Mesto*', 'city');
			echo form_input('city',set_value('city')).'</p>';
			echo form_error('country');
			echo '<p>'.form_label('Štát*', 'country');
			echo form_input('country',set_value('country')).'</p>';
			echo form_error('organization');
			echo '<p>'.form_label('Organizácia*', 'organization');
			echo form_input('organization',set_value('organization')).'</p>';
			echo form_error('date_of_arrival');
			echo '<p>'.form_label('Dátum príchodu*', 'date_of_arrival');
			echo form_input(array('name'=>'date_of_arrival', 'class'=>'date'),set_value('date_of_arrival')).'<small>rok-mesiac-den</small></p>';
			echo form_error('date_of_departure');
			echo '<p>'.form_label('Dátum odchodu*', 'date_of_departure');
			echo form_input(array('name'=>'date_of_departure', 'class'=>'date'),set_value('date_of_departure')).'<small>rok-mesiac-den</small></p>';
			echo form_hidden('types','odcestovani');
			echo form_hidden('unique',$unique);
			echo '<p>'.form_submit('submit', 'Pridať').'</p>';
			echo "<small>Údaje označené * sú povinné!</small>";
			echo form_fieldset_close(); 
		echo form_close();
		}
	 ?>


<?php
$footer_scripts = '<script type="text/javascript">
jQuery(document).ready(function($) {
    $(\'input[type=text][name=date_of_arrival], input[type=text][name=date_of_departure]\').datepicker({ dateFormat: \'yy-mm-dd\', changeMonth: true, changeYear: true, numberOfMonths: 2, showButtonPanel: true, firstDay: 1, showWeek: true, showOtherMonths: true, selectOtherMonths: true });
    $(\'input[type=text][name=city]\').autocomplete({ source: \'' . site_url('SluzobneCesty/cities') . '\' });
    $(\'input[type=text][name=country]\').autocomplete({ source: \'' . site_url('SluzobneCesty/countries') . '\' });
    $(\'input[type=text][name=organization]\').autocomplete({ source: \'' . site_url('SluzobneCesty/organizations') . '\' });
});
</script>';

$footer_scripts .= '<script type="text/javascript">
jQuery(document).ready(function($) {
    $(\'#page_selector\').change(function(){
        $(\'#pagination_form\').submit();
    });
    $(\'#per_page_selector\').change(function(){
        $(\'#pagination_form\').submit();
    });
    $(\'#filter_form input[name="filter[date]"]\').datepicker({ dateFormat: \'yy-mm-dd\', changeMonth: true, changeYear: true, showButtonPanel: true, firstDay: 1, showWeek: true, showOtherMonths: true, selectOtherMonths: true, yearRange: \'-150:+20\' });
});
</script>';

include_once('footer.php');
?>
